package terminal.gui;

import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.jface.viewers.CheckboxTreeViewer;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.swt.widgets.TreeColumn;

public class Test extends Dialog {

	protected Object result;
	protected Shell shlDane;

	/**
	 * Create the dialog.
	 * @param parent
	 * @param style
	 */
	public Test(Shell parent, int style) {
		super(parent, style);
		setText("SWT Dialog");
	}

	/**
	 * Open the dialog.
	 * @return the result
	 */
	public Object open() {
		createContents();
		shlDane.open();
		shlDane.layout();
		Display display = getParent().getDisplay();
		while (!shlDane.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		return result;
	}

	/**
	 * Create contents of the dialog.
	 */
	private void createContents() {
		shlDane = new Shell(getParent(), getStyle());
		shlDane.setSize(450, 421);
		shlDane.setText("Dane");
		shlDane.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		Group group = new Group(shlDane, SWT.NONE);
		group.setLayout(new FormLayout());
		
		final Combo combo = new Combo(group, SWT.NONE);
		combo.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				System.out.println(combo.getSelection());
			}
		});
		FormData fd_combo = new FormData();
		fd_combo.right = new FormAttachment(0, 438);
		fd_combo.top = new FormAttachment(0);
		fd_combo.left = new FormAttachment(0);
		combo.setLayoutData(fd_combo);
		combo.setItems(new String[] {"", "Okregowe komisje wyborcze", "Czlonkowie komisji", "Glosujacy", "Karty wyborcze"});
		
		Composite composite = new Composite(group, SWT.NONE);
		FormData fd_composite = new FormData();
		fd_composite.top = new FormAttachment(combo, 236);
		fd_composite.bottom = new FormAttachment(100, -28);
		fd_composite.left = new FormAttachment(combo, 0, SWT.LEFT);
		fd_composite.right = new FormAttachment(combo, 0, SWT.RIGHT);
		composite.setLayoutData(fd_composite);
		composite.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		Button btnAdd = new Button(composite, SWT.NONE);
		btnAdd.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
			}
		});
		btnAdd.setText("Dodaj");
		
		Button btnEdit = new Button(composite, SWT.NONE);
		btnEdit.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
			}
		});
		btnEdit.setText("Edytuj");
		
		Button btnDelete = new Button(composite, SWT.NONE);
		btnDelete.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
			}
		});
		btnDelete.setText("Usun");
		
		CheckboxTreeViewer checkboxTreeViewer = new CheckboxTreeViewer(group, SWT.BORDER);
		Tree tree = checkboxTreeViewer.getTree();
		FormData fd_tree = new FormData();
		fd_tree.bottom = new FormAttachment(combo, 193, SWT.BOTTOM);
		fd_tree.right = new FormAttachment(combo, 0, SWT.RIGHT);
		fd_tree.top = new FormAttachment(combo, 6);
		fd_tree.left = new FormAttachment(0);
		tree.setLayoutData(fd_tree);
		
		TreeItem trtmNewTreeitem = new TreeItem(tree, SWT.NONE);
		trtmNewTreeitem.setText("New TreeItem");

	}
}
